package com.csi.bumblebee.service.impl;

import com.csi.bumblebee.domain.user.Submit;
import com.csi.bumblebee.mapper.SubmitMapper;
import com.csi.bumblebee.domain.vo.SubmitVo;
import com.csi.bumblebee.service.SubmitService;
import com.csi.bumblebee.util.IdUtil;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 投递记录表
 *
 * @author wdl
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SubmitServiceImpl implements SubmitService {

    @Autowired
    private SubmitMapper submitMapper;


    /**
     * 查询学生的投递记录集合
     *
     * @return 学生投递记录vo对象
     */
    @Override
    public List<SubmitVo> listSubmit(String id) {

        if (id != null) {
            return this.submitMapper.listSubmit(id);
        }

        return null;
    }

    @Override
    public List<Submit> checkCount(Submit submit) {
        return submitMapper.checkCount(submit);
    }

    @Override
    public int insert(Submit submit) {
        List<Submit> submits = submitMapper.checkCount(submit);
        int result = 0;
        if (submits != null && submits.size() == 0) {
            submit.setId(IdUtil.getString(Submit.PRE_NAME));
            result = submitMapper.insert(submit);
        }
        return result;
    }

}
